num=int(input())
if num<1000 or num>9999:
    print(0)
else:
    result=0
    a=str(num//1000)
    b=str(num%1000//100)
    c=str(num//10%10)
    d=str(num%10)
    sp=[a,b,c,d,a+b,a+c,a+d,b+c,b+d,c+d,a+b+c,a+b+d,b+c+d,a+b+c+d]
    sp=[int(x) for x in sp]
    for el in sp:
        flag=True
        if el<=1:
            flag=False
        for i in range(2, int(el**0.5)+1):
            if el%i==0:
                flag=False
        if flagand el>result:
            result=rl
    print(result)
